package myhashmap;

public class MyList {
	private Entry[] pairList=new Entry[100];
	private int currentPosition=0;
	private int lenth=100;
	
	
	public  int getByKey(int key){
		int value=0;
		for (int i = 0; i < currentPosition; i++) {
			if (pairList[i].getKey()==key){
				value=pairList[i].getValue();
				break;
			}
		}
		return value;
	}
	
	public void add(Entry pair){
		pairList[currentPosition]=pair;
		currentPosition++;
		
		if (currentPosition>(lenth*0.8)) {
			rebuild();
		}
	}
	private void rebuild() {
		this.lenth=this.lenth*3/2;
		Entry[] pairResList=new Entry[lenth];
		for (int i = 0; i < currentPosition; i++) {
			pairResList[i]=pairList[i];
		}
		pairResList=pairResList;
	}
	
	public void removeByKey(int key){
		int position=0;
		while ((position<lenth)&&(pairList[position].getKey()!=key)){
			position++;
		}
		if (position<lenth){
			for (int i = position; i<lenth-1; i++) {
				pairList[i]=pairList[i+1];
			}
			currentPosition--;
		}
	}
}
